//
//  AddAnnounceViewController.m
//  YiBaoStore
//
//  Created by 吕清毅 on 2018/10/5.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "AddAnnounceViewController.h"

@interface AddAnnounceViewController ()<UITextViewDelegate>

@end

@implementation AddAnnounceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = HexWithAlpha(0x000000, 0.3);
    [self setMainView];
}

- (void)setMainView
{
    float padding = (SCREENHEIGHT-180)/2;
    UIView *backView = [UIView new];
    backView.frame = CGRectMake(50, padding, SCREENWIDTH-100, 180);
    backView.backgroundColor = TotalWhite;
    backView.layer.cornerRadius = 12;
    backView.layer.masksToBounds = YES;
    backView.userInteractionEnabled = YES;
    [self.view addSubview:backView];

    UIImageView *leftIV = [UIImageView new];
    leftIV.frame = CGRectMake(15, 15, 24, 20);
    leftIV.image = [UIImage imageNamed:@"gonggao"];
    [backView addSubview:leftIV];
    
    UILabel *addLabel = [UILabel new];
    addLabel.frame = CGRectMake(leftIV.right+10, 20, 55, 14);
    addLabel.textColor = titleColor;
    addLabel.font = FontSemiboldSize(14);
    addLabel.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:-0.7 and:@"添加公告"];
    [backView addSubview:addLabel];
    
    UIButton *rightIV = [UIButton buttonWithType:UIButtonTypeCustom];
    rightIV.frame = CGRectMake(backView.width-36, 20, 16, 16);
    [rightIV setImage:[UIImage imageNamed:@"anClose"] forState:UIControlStateNormal];
    [rightIV addTarget:self action:@selector(closeBtn:) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:rightIV];
    
//    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    closeBtn.frame = CGRectMake(backView.width-40, 10, 35, 35);
//    closeBtn.backgroundColor = [UIColor redColor];
//    [closeBtn addTarget:self action:@selector(closeBtn:) forControlEvents:UIControlEventTouchUpInside];
   // [backView addSubview:closeBtn];
    
    UITextView *addTV = [UITextView new];
    addTV.frame = CGRectMake(20, addLabel.bottom+15, backView.width-40, 60);
    addTV.delegate = self;
    addTV.tag = 50;
    addTV.textColor = titleColor;
    //UIColorFromHex(0xD3D3D3);
    addTV.font = FontWithSize(12);
    addTV.backgroundColor = UIColorFromHex(0xF4F4F4);
    [backView addSubview:addTV];
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sureBtn.frame = CGRectMake(0, backView.height-44, backView.width, 44);
    sureBtn.backgroundColor = UIColorFromHex(0xF7D553);
    [sureBtn setAttributedTitle:[TTKUtil getAtttributeStringWithLineSpace:0 kern:-0.6 and:@"确认发布"] forState:UIControlStateNormal];
    [sureBtn setTitleColor:titleColor forState:UIControlStateNormal];
    sureBtn.titleLabel.font = FontSemiboldSize(12);
    [sureBtn addTarget:self action:@selector(sureBtn:) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:sureBtn];
     
}

- (void)closeBtn:(UIButton *)btn
{
    NSLog(@"close");
     [self.view removeFromSuperview];
}

- (void)sureBtn:(UIButton *)btn
{
    UITextView *tv =(UITextView *)[self.view viewWithTag:50];
    NSString *title = tv.text;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:title forKey:@"title"];
    [HttpRequest formPostPath:Notice_Add_API params:dict resultBlock:^(id Data, MsgModel *msgModel) {
       
        NSLog(@"添加成功");
        [[NSNotificationCenter defaultCenter]postNotificationName:NoticeRefresh object:nil];
        [self.view removeFromSuperview];
    }];
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车，即按下return
        //在这里做你响应return键的代码
        [textView resignFirstResponder];
        return NO; //这里返回NO，就代表return键值失效，即页面上按下return，不会出现换行，如果为yes，则输入页面会换行
    }
    return YES;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
